M3U Playlist Maker – English Documentation

Part 1 – Database, Helpers & RDJDATA Builder

Database connection

The function getPdo() creates a PDO connection to the MySQL database using UTF8MB4 encoding and exception-based error handling. It uses global configuration variables for host, database name, user, password and port.

Cue parser (RadioDJ format)

parseCueTimes($cueString) parses a RadioDJ-style cue string (e.g. sta=0&int=5&out=180) into an associative array with keys like sta, int, out, end, etc. If the string is empty or only &, it returns default values (all zeros).

Energy score

getEnergyScore($track) calculates a 0–10 “energy score” based on BPM and intro/outro length. Higher BPM and shorter intros/outros increase the score. This is later used to sort the playlist into a smoother “energy flow”.

Sweeper ID extraction

extractSweeperId($value) strips a leading & from a sweeper reference and returns an empty string if no sweeper is present.

RDJDATA line builder

buildRDJDataLine($track) builds a #RDJDATA: line containing: track ID, cue points (start, intro, end, outro, hooks, etc.) and an optional sweeper ID. This line is written into the M3U so RadioDJ can read cue data directly from the playlist.

Part 2 – Playlist Generator, M3U Writer & Energy Sorting

BPM preset mode

In preset mode (when bpmmode is not manual), the script:

M3U writing (preset mode)

After selecting tracks, the script writes an M3U file:

It logs the filename, track count and total duration, and returns these values.

Manual mode

In manual mode, the script:

It then tries to fill the target duration as closely as possible, first by adding tracks, then by fine-tuning the remaining seconds with exact or near matches.

Energy-wave sorting

Once the playlist is built, it is sorted using getEnergyScore() into a “wave” pattern: medium-energy tracks near the center, higher/lower energy tracks towards the edges. If two tracks have the same wave value, tie-breaking uses outro length and then intro length to improve transitions.

M3U writing (manual mode)

The final playlist is written to an M3U file in the same format: #EXTM3U, followed by #EXTINF, path and #RDJDATA for each track.

Part 3 – HTML Interface, Form Handling & Filters

Hard reset

If the user submits the form with a reset field, the script redirects to the same URL without query parameters, effectively clearing the form and state.

Folders, log file and M3U list

The script sets up:

Genre list

It loads all genres from the genre table and uses them to populate a multi-select list in the UI.

Form handling

On POST, the script:

Part 4 – M3U Remixer & New Playlist Generation

M3U remixer

If the user selects an existing M3U file and enters a new filename:

New playlist generation

If no M3U is chosen, the script:

Preview

When ?done=filename.m3u is present, the script:

Part 5 – UI Form, Remix Section, Preview & Scroll-to-Top

Playlist filter fields

The HTML form includes:

Submitting this form without choosing an existing M3U triggers new playlist generation.

Remix existing M3U

A second fieldset lets the user:

Preview and reset

If a playlist was created or remixed, the page shows:

Scroll-to-top button

A small floating button appears when the user scrolls down. It:

This completes the full English documentation of your M3U Maker: database, helpers, playlist logic, M3U writing, remixing, UI and preview.